package org.workplicity.cia.ui.honeycomb;

import org.workplicity.cia.ui.honeycomb.fragments.HandoffFragment;
import org.workplicity.cia.ui.honeycomb.fragments.LogFragment;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class MainFrameActivity extends Activity {
    /** Called when the activity is first created. */
	
	private View mActionBarView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        
        ActionBar bar = getActionBar();
        

        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        
        ActionBar.Tab tabA = bar.newTab().setText("Logs");
        ActionBar.Tab tabB = bar.newTab().setText("Handoffs");

        Fragment logFrag = new LogFragment();
        Fragment handoffFrag = new HandoffFragment();
        
        tabA.setTabListener(new MyTabListener(logFrag));
        tabB.setTabListener(new MyTabListener(handoffFrag));
        
        bar.addTab(tabA);
        bar.addTab(tabB);
        
        // spinners
        Spinner userSpinner = (Spinner) findViewById(R.id.tab1toprowUser);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.user_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        userSpinner.setAdapter(adapter);
        
        Spinner typeSpinner = (Spinner) findViewById(R.id.tab1toprowType);
        ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.type_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        typeSpinner.setAdapter(adapter2);
        
        Spinner statusSpinner = (Spinner) findViewById(R.id.tab1toprowStatus);
        ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.status_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        statusSpinner.setAdapter(adapter3);


    }

	
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }
	
	protected class MyTabListener implements ActionBar.TabListener {
        private Fragment mFragment;

        // Called to create an instance of the listener when adding a new tab
        public MyTabListener(Fragment fragment) {
            mFragment = fragment;
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ft.add(R.id.fragments, mFragment, null);
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(mFragment);
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // do nothing
        }

    }
    
    
}